*********************************
***  Trump paper - POWER CALCULATIONS
*** Created: 31/10/2020
*** Last updated: 21/05/2021
clear all
set scheme plottig
 

	local user = 1		/* user 1 = sergi, user 2 = Anja */

	if `user' == 1 {			// input relevant file path as per your computer

		global		main "/Users/aneundorf/Dropbox/Project_Populism/BA project/Analysis/Trump_Replication files/"
		global 		graphs 			"${main}Graphs/"
		global 		results			"${main}Results/"
	}

cd "${main}"
***------------------------------
** ANES 2016 - Downloaded from https://electionstudies.org/data-center/2016-time-series-study/

use "Data/anes_timeseries_2016.dta", clear


************************
***Power calculations***
************************

gen trump_feeling=V161087
replace trump_feeling=. if trump_feeling<0

gen clinton_feeling=V161086
replace clinton_feeling=. if clinton_feeling<0

sum trump_feeling, d
gen trump_feeling01 = (trump_feeling-r(min))/(r(max)-r(min))

sum clinton_feeling, d
gen clinton_feeling01 = (clinton_feeling-r(min))/(r(max)-r(min))

sum trump_feeling01 clinton_feeling01

gen partyid=V161158x  
replace partyid=. if partyid<1

recode partyid 1/2=1 3/5=2 6/7=3, gen(partyid_cat)


*Power calculations for average treatment effects (4 groups, assuming 95% confidence intervals, 10% magnitude size effects, 80% power)

dis 0.1/0.33 /*standardized difference = difference between means / standard deviation of Trump feeling. According to table, assuming alpha=0.05 and power 80%, we need 176 per group. */
dis 176*4 /*this is the total required N for average effects (4 groups): 704*/

*Power calculations for partisanship analysis: 

bysort partyid_cat: sum trump_feeling01, d /*on the basis of ANES, we assume difference of 25% (which was the difference in Trump feeling between Republicans and independents; probably conservative as difference between democrats and republicans is much larger)*/


dis 0.25/0.25 /*standardized difference = difference between means / standard deviation. Lets' assume 0.25, which is the std deviation of Trump feeling for Democrats and Republicans. According to table, assuming alpha=0.05 and power 80%, we need 17 per group. */


dis 17*4*3
